package com.tjsinfo.tjsoa.addresslist.action;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.addresslist.bo.IAddressListAndFilePendingBo;
import com.tjsinfo.tjsoa.addresslist.bo.IAddressListUserBo;
import com.tjsinfo.tjsoa.addresslist.vo.AddressListAndFilePending;
import com.tjsinfo.tjsoa.system.bo.ISystemUserBo;
import com.tjsinfo.tjsoa.system.vo.User;

public class toSynchronizationAction extends Action{
	private IAddressListUserBo userBo;
	private ISystemUserBo systemUserBo;
	private IAddressListAndFilePendingBo addressListAndFilePendingBo;
	
	public void setAddressListAndFilePendingBo(
			IAddressListAndFilePendingBo addressListAndFilePendingBo) {
		this.addressListAndFilePendingBo = addressListAndFilePendingBo;
	}
	public void setUserBo(IAddressListUserBo userBo) {
		this.userBo = userBo;
	}
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		String returnString = request.getParameter("returnString");
		List list = userBo.getAddresssListUserByUserId(Integer.valueOf(user.getUser_id()));
		
		List weilist = addressListAndFilePendingBo.findBySendUserIdAndTitle(user.getUser_id(), "个人信息同步");
		List weilist1 = new ArrayList();
		Integer[] ids = new Integer[weilist.size()];
		int i = 0;
		for (Iterator iterator = weilist.iterator(); iterator.hasNext();) {
			AddressListAndFilePending pending = (AddressListAndFilePending) iterator.next();
			ids[i] = pending.getTjsUserId();
			i++;
		}
		if(ids.length>0){
			weilist1 = systemUserBo.findInUserIds(ids);
		}
		request.setAttribute("list", list);
		request.setAttribute("weilist", weilist1);
		request.setAttribute("returnString", returnString);
		return mapping.findForward("ok");
	}
	public void setSystemUserBo(ISystemUserBo systemUserBo) {
		this.systemUserBo = systemUserBo;
	}
}
